<?php

declare(strict_types=1);

/**
 * @Author:     Frank
 * @contact     frank_hhm@163.com
 * @Date:       2023-02-06 21:20:17
 * @Last Modified time: 2023-02-20 11:24:12
 */
namespace app\common\model\store;

use frank\base\BaseModel;
use frank\traits\ModelTrait;
use app\common\enum\EnumFactory;

/**
 * 订单商品
 * Class OrderGoodsModel
 * @package app\common\model\store
 */
class OrderGoodsModel extends BaseModel
{
    use ModelTrait;

    /**
     * 数据表主键
     */
    protected $pk = 'id';

    /**
     * 模型名称
     */
    protected $name = 'store_order_goods';


    /**
     * 商品原表
     * @return \think\model\relation\HasMany
     */
    public function goods()
    {
        return $this->hasOne("app\\common\\model\\store\\GoodsModel",'id','goods_id');
    }


    /**
     * 售后状态修改器
     */
    public function getRefundStatusAttr($value)
    {
        return EnumFactory::instance('store.order.refund_status')->getItem($value);
    }

    /**
     * order_id搜索器
     */
    public function searchOrderIdAttr($query, $value)
    {
        if (is_array($value)) {
            $query->whereIn('order_id', $value);
        } else {
            $query->where('order_id', $value);
        }
    }

    /**
     * id搜索器
     */
    public function searchIdAttr($query, $value)
    {
        if (is_array($value)) {
            $query->whereIn('id', $value);
        } else {
            $query->where('id', $value);
        }
    }
}

